//
//  HLIMKitTipContentConfig.m
//  YueYue
//
//  Created by hulu001 on 2024/1/12.
//

#import "HLIMKitTipContentConfig.h"

#import "HLChatKit.h"
#import "M80AttributedLabel.h"

@interface HLIMKitTipContentConfig ()

@property (strong, nonatomic) M80AttributedLabel *contentLabel;

@end

@implementation HLIMKitTipContentConfig


/// 计算气泡尺寸
/// @param cellWidth cell的宽
/// @param message 消息
- (CGSize)contentSize:(CGFloat)cellWidth message:(NIMMessage *)message
{
    HLIMKitMessageSetting *setting = [HLChatKit.shareSDK.config setting:message];
    self.contentLabel.font = setting.font;
    
    if (message.messageType == NIMMessageTypeTip) {
        NSDictionary *ext = message.localExt;
        if ([ext[@"TipType"] isEqualToString:@"1"]) {
            return CGSizeMake(cellWidth, 33 + 27);
        } else {
            CGSize size = [message.text boundingRectWithSize:CGSizeMake(280, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil].size;
            return CGSizeMake(cellWidth, size.height + 27);
        }
    }
    
    return CGSizeMake(200, 33);
}

/// content view 的名字（一般是类名）
/// @param message 消息
- (NSString *)cellContent:(NIMMessage *)message
{
    return @"HLIMKitMessageTipContentView";
}

/// cell内容距离气泡的内间距
/// @param message 消息
- (UIEdgeInsets)contentViewInsets:(NIMMessage *)message;
{
    return [[HLChatKit.shareSDK config] setting:message].contentInsets;
}

#pragma mark - contentLabel

- (M80AttributedLabel *)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[M80AttributedLabel alloc] initWithFrame:CGRectZero];
        _contentLabel.backgroundColor = UIColor.clearColor;
        _contentLabel.font = [UIFont systemFontOfSize:16.f];
    }
    return _contentLabel;
}


@end
